<?php 
require_once("_ClsCon.php");
$db = new MySQLi('localhost','root','12345','notarios');
$_obj   = new _ClsCon();        
  	$estado 			= $_POST['estado'];
	$descrio 			= $_REQUEST['descrio'];
	$dnilib 			= $_REQUEST['dnilib'];
	$crono				= $_REQUEST['crono'];
	$rangof1 	 		= $_REQUEST['rangof1'];
	$rangof2  			= $_REQUEST['rangof2'];
	$db = new MySQLi('localhost','root','12345','notarios');
	$limite				= $_POST['limite'];

	$query2 = "SELECT numlibro FROM libros";
	$res2=$db->query($query2);
	$total=$res2->num_rows;
	
	$paginas=ceil($total/17);
	
    $query = "CALL spLisLibros('".$descrio."' ,'".$dnilib."' ,'".$crono."' ,'".$rangof1."','".$rangof2."','".$estado."',".$limite.")";
	
	$res = $db->query($query);
	//var_dump($consulta_libros);
	//exit();
	
if($res2->num_rows){
	while ($rowkar = $res->fetch_array())
{
	
		
	$nomyape=strtoupper($rowkar['c_descontrat']);
	$textorefe=str_replace("?","'",$nomyape);
	$textoampers=str_replace("*","&",$textorefe);
	$textoamperss=str_replace("ñ","Ñ",$textoampers);
	$refii=strtoupper($textoamperss);
	
	
	if ($rowkar['tipper']=="N"){

	$nomyape=strtoupper($rowkar['apepat']." ".$rowkar['apemat']." ".$rowkar['prinom']." ".$rowkar['segnom']);
	$textorefe=str_replace("?","'",$nomyape);
	$textoampers=str_replace("*","&",$textorefe);
	$textoamperss=str_replace("ñ","Ñ",$textoampers);
	$refii=strtoupper($textoamperss);
		} else{
			$nomyape=strtoupper( $rowkar['empresa']);
			$textorefe=str_replace("?","'",$nomyape);
			$textoampers=str_replace("*","&",$textorefe);
			$textoamperss=str_replace("ñ","Ñ",$textoampers);
			$refii=strtoupper($textoamperss);

		}

$fecing = $rowkar['fecing'];
$fecing1 = explode ("-",$fecing);
$fecing2 = $fecing1[2] . "/" . $fecing1[1] . "/" . $fecing1[0];

$libros[$rowkar['numlibro']]= "<table width='823' border='1' cellpadding='0' cellspacing='0' bordercolor='#333333'>
  <tr>
  
  
    <td width='79' align='center'><span class='titubuskar0'>".$rowkar['numlibro']."-".$rowkar['ano']."</span></td>
    <td width='84' align='center'><span class='titubuskar0'>".$fecing2."</span></td>
    <td width='153' align='center'><span class='titubuskar0'>".$refii."</span></td>
    <td width='116' align='center'><span class='titubuskar0'>".$rowkar['destiplib']."</span></td>
    <td width='101' align='center'><span class='titubuskar0'>".$rowkar['desnlibro']."</span></td>
    <td width='68' align='center'><span class='titubuskar0'>".$rowkar['folio']."</span></td>
    <td width='101' align='center'><span class='titubuskar0'>".$rowkar['destipfol']."</span></td>
    <td width='73' align='center'><span class='titubuskar0'>".$rowkar['ruc']."</span></td>
    <td width='25' align='center'><a href='verlibro.php?numlibro=".$rowkar['numlibro']."'><img src='iconos/verkar.png' width='30' height='31' border='0'></a></td>
  </tr>
</table>";

}
}

foreach($libros as $lib){
	
	echo "<article >".$lib."</article>";
	}		

echo "<table width='300' border='0' cellspacing='0'cellpadding='0'>
  <tr>
    <td width='45'>"; if ($limite>0){
	
	$limit=$limite-17;
	echo "<input type='hidden' value='".$limit."' id='_imagen' /><aside onClick=\"cargakardex(".$limit.")\"><img src='ante.png' width='37' height='36' border='0' title='Anterior'></aside>";
	
	}else{
		echo "<input type='hidden' value='".$limit."' id='_imagen' /><aside></aside>";
		} echo"</td>
    <td width='100'>";
			echo "total de pag."." ".$paginas;
			echo"</td>
    <td width='45'>"; 
	
	if ($limite<$total-17){
	
	$limit=$limite+17;
	echo "<aside onClick=\"cargakardex(".$limit.")\"><img  src='sigte.png' width='37' height='36' border='0' title='Siguiente'></aside>";
	
	}else{
		echo "<aside></aside>";
		}
	
	echo"</td>
  </tr>
</table>";

?>